<template>
    <div class="certified">
        <el-card class="box-card">
            <a-alert message="您所填写的信息仅用于实名认证，平台对于您的信息严格保密。" type="info" show-icon />
            <div class="FormCode">
                <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="150px" class="demo-ruleForm"
                    :size="formSize" status-icon>
                    <el-form-item label="企业名称" prop="name">
                        <el-input v-model="ruleForm.name" placeholder="请输入企业名称" />
                    </el-form-item>
                    <el-form-item label="统一社会信用代码" prop="region">
                        <el-input v-model="ruleForm.name" placeholder="请输入统一社会信用代码" />
                    </el-form-item>
                    <el-form-item label="法人姓名" prop="count">
                        <el-input v-model="ruleForm.name" placeholder="请输入法人姓名" />
                    </el-form-item>
                    <el-form-item label="法人身份证号" prop="count">
                        <el-input v-model="ruleForm.name" placeholder="请输入法人身份证号" />
                    </el-form-item>
                    <el-form-item label="个人电子邮箱" prop="count">
                        <el-input v-model="ruleForm.name" placeholder="请输入个人电子邮箱" />
                    </el-form-item>
                    <el-form-item label="个人手机号码" prop="count">
                        <el-input v-model="ruleForm.name" placeholder="请输入个人手机号码" />
                    </el-form-item>
                    <el-form-item label="营业执照照片" prop="name">
                        <div>
                            <el-button>选择图片</el-button><br />
                            <div>图片大小需小于10M，支持文件格式为jpg，jpeg，png</div>
                        </div>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm(ruleFormRef)">
                            提交
                        </el-button>
                        <el-button @click="resetForm(ruleFormRef)">取消</el-button>
                    </el-form-item>
                </el-form>
            </div>

        </el-card>

    </div>
</template>

<script lang="ts" setup>
import 'ant-design-vue/dist/antd.css';
import { reactive, ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive({
    name: '',
    region: '',
    count: '',
    date1: '',
    date2: '',
    delivery: false,
    type: [],
    resource: '',
    desc: '',
})

const rules = reactive<FormRules>({
    name: [
        { required: true, message: 'Please input Activity name', trigger: 'blur' },
        { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
    ],
    region: [
        {
            required: true,
            message: 'Please select Activity zone',
            trigger: 'change',
        },
    ],
    count: [
        {
            required: true,
            message: 'Please select Activity count',
            trigger: 'change',
        },
    ],
    date1: [
        {
            type: 'date',
            required: true,
            message: 'Please pick a date',
            trigger: 'change',
        },
    ],
    date2: [
        {
            type: 'date',
            required: true,
            message: 'Please pick a time',
            trigger: 'change',
        },
    ],
    type: [
        {
            type: 'array',
            required: true,
            message: 'Please select at least one activity type',
            trigger: 'change',
        },
    ],
    resource: [
        {
            required: true,
            message: 'Please select activity resource',
            trigger: 'change',
        },
    ],
    desc: [
        { required: true, message: 'Please input activity form', trigger: 'blur' },
    ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            console.log('submit!')
        } else {
            console.log('error submit!', fields)
        }
    })
}

const resetForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return
    formEl.resetFields()
}

const options = Array.from({ length: 10000 }).map((_, idx) => ({
    value: `${idx + 1}`,
    label: `${idx + 1}`,
}))
</script>

<style scoped>
.certified {
    padding: 30px 40px;
}

.box-card {
    width: 100%;
}

.FormCode {
    width: 40%;
    position: relative;
    left: 150px;
    top: 50px;
    min-height: 480px;
}
</style>